package com.pixeljet.html5.client;

import com.google.gwt.core.client.JavaScriptObject;

public final class File extends JavaScriptObject {

	protected File() {}
	
	public native String getName() /*-{
		return this.name;
	}-*/;
	
	public native String getBase64data() /*-{
		return this.base64data;
	}-*/;
	
	public String getFileExtension() {
		final String name = getName();
		String[] tokens = name.split("\\.");
		if(tokens!=null) {
			return tokens[tokens.length-1];
		} else {
			return name;
		}
	}
	
	public boolean hasImageExtension() {
		
		final String fileExtension = getFileExtension();
		String[] extensions = {"png", "gif", "jpeg", "jpg"};
		for(String extension: extensions) {
			if(fileExtension.equalsIgnoreCase(extension))
				return true;
		}
		return false;
	}
}
